/********************************************
 * 功能说明: 
 * 模块名称: 
 * 系统名称: 
 * 软件版权: Frank
 * 系统版本: 1.0.0
 * 开发人员: Frank
 * 开发时间: 2019/8/13 10:47
 * 审核人员: 
 * 相关文档: 
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.spring.arch.uaa.model;

import com.spring.arch.common.jpa.model.AbstractLogicalModel;
import com.spring.arch.uaa.enums.OrganizationType;
import com.spring.arch.common.jpa.model.AbstractLogicalModel;
import com.spring.arch.uaa.enums.OrganizationType;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * <b>组织机构</b>
 * <br/>
 * 集团 -> 大区 -> 公司 -> 项目 -> 部门 -> 组
 *
 * @author Frank
 * @version 1.0.0.1
 * @since JDK 1.8
 */
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "organization")
public class Organization extends AbstractLogicalModel {

    private static final long serialVersionUID = 3133209894670521298L;

    /**
     * 所属租户
     */
    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    private Tenant tenant;

    /**
     * 父级组织
     */
    @ManyToOne(fetch = FetchType.LAZY)
    private Organization parent;

    /**
     * 所属项目
     */
    @ManyToOne(fetch = FetchType.LAZY)
    private Project project;

    /**
     * 组织编码
     */
    @NotBlank
    @Size(max = 32)
    @Column(unique = true, nullable = false)
    private String code;

    /**
     * 组织名称
     */
    @NotBlank
    @Size(max = 64)
    @Column(nullable = false)
    private String name;

    /**
     * 组织类型
     */
    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(length = 32)
    private OrganizationType type;

    public Organization(Tenant tenant,
                        Organization parent,
                        Project project,
                        String code,
                        String name,
                        OrganizationType type) {
        this.tenant = tenant;
        this.parent = parent;
        this.project = project;
        this.code = code;
        this.name = name;
        this.type = type;
    }
}
